package ch03
{
	import flash.display.Sprite;
	import flash.events.Event;
	import utils.Ball;

	/**
	 * 圆形运动
	 * 用正弦函数计算 y ，用余弦函数计算 x
	 * @author jianping.shenjp
	 *
	 */
	public class Circle extends Sprite
	{
		private var ball:Ball;
		private var angle:Number=0;
		private var centerX:Number=200;
		private var centerY:Number=200;
		private var radius:Number=50;
		private var speed:Number=.1;

		public function Circle()
		{
			init();
		}

		private function init():void
		{
			ball=new Ball();
			addChild(ball);
			ball.x=0;
			addEventListener(Event.ENTER_FRAME, onEnterFrame);
		}

		public function onEnterFrame(event:Event):void
		{
			/**
			 * 用正弦函数计算 y ，用余弦函数计算 x
			 * */
			ball.x=centerX + Math.cos(angle) * radius;
			ball.y=centerY + Math.sin(angle) * radius;
			angle+=speed;
		}
	}
}